<?php session_start();?>
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<?php
$dsn='mysql:dbname=end;host=localhost';
$user='root';
$psws='123456';
$users=$_POST['username'];
$pass=$_POST['psw'];
try{
    $db=new PDO($dsn,$user,$psws);
    $sql="SELECT username,passwords FROM table_company WHERE username='$users' AND passwords='$pass'";
    $result=$db->query($sql)->fetch();
    if($result==false)
    {
        $x=0;
        throw new PDOException("登录失败",501);
    }
    else{
        echo "登录成功";
        $x=1;
    }
}catch(PDOException $e){
    if($e->getCode()>500)
        echo "SQL failed".$e->getMessage();
    else
        echo "Connect failed".$e->getMessage();

}
?>
<script>
    function Return() {
        window.location.href="./login.php";
    }
    function Return1() {
        window.location.href="./company.php";
    }
    window.onload=function() {
        var x=<?php echo $x;?>;
        if(x==0) {
            setTimeout(Return,3000);
        }else if(x==1) {
            setTimeout(Return1,3000);
        }
    }
</script>
</body>
</html>
